import 'package:flutter/material.dart';
import 'package:flutter_getx/app/routes/app_pages.dart';
import 'package:get/get.dart';

import '../../../../const.dart';
import '../controllers/me_controller.dart';

class MeView extends GetView<MeController> {
  GestureDetector buildInfoTile(String title, String? content, Function callback) {
    return GestureDetector(
      onTap: () {
        callback();
      },
      child: Padding(
        padding: const EdgeInsets.only(top: 5, bottom: 6),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(color: Colors.grey),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                if (content == null)
                  Text("空")
                else
                Text(content),
                Icon(
                  Icons.arrow_right,
                  color: Colors.grey,
                )
              ],
            )
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Obx(()=>Scaffold(
        appBar: AppBar(
          title: Text('我的'),
          centerTitle: true,
        ),
        body:  Container(
          color: bgColor,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                children: [
                  GestureDetector(
                    onTap: () {
                      controller.getImageFromGallery();
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(10),
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(13),
                        child:
                        controller.userInfoService.userInfo.value.avatar == null || controller.userInfoService.userInfo.value.avatar == ''? Icon(Icons.account_circle_rounded, size: 60,color: Colors.blue,)
                            :Image.network(
                          controller.userInfoService.userInfo.value.avatar!,
                          width: 106,
                        ),
                      ),
                    ),
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        controller.userInfoService.userInfo.value.nickname?? "nickname",
                        style: TextStyle(
                            fontWeight: FontWeight.w500, fontSize: 22),
                      ),
                      Row(
                        children: [
                          Text('完善资料，让更多人了解你'),
                          GestureDetector(
                            onTap: () {
                              Get.toNamed(Routes.EDIT_ME);
                            },
                            child: Padding(
                              padding: const EdgeInsets.all(8.0),
                              child: Icon(Icons.edit_note, color: Colors.blue,),
                            ),
                          ),
                        ],
                      )
                    ],
                  )
                ],
              ),
              controller.userInfoService.userInfo.value.id == null ? Container() :SizedBox(
                width: Get.width * .94,
                child: Card(
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(12)),
                  elevation: 2,
                  child: Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        buildInfoTile('账号', controller.userInfoService.userInfo.value.id.toString(), () {}),
                        buildInfoTile('性别', controller.userInfoService.userInfo.value.gender == true? "男": "女", () {}),
                        buildInfoTile('生日', controller.userInfoService.userInfo.value.birthday, () {}),
                        buildInfoTile('个人签名',controller.userInfoService.userInfo.value.intro , () {}),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        )
    ));
  }
}
